package com.qianli.cashmama.trade.dao.impl;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.qianli.cashmama.trade.dao.TBillDao;
import com.qianli.cashmama.trade.entity.TBillDeductFixEntity;
import com.qianli.cashmama.trade.entity.TBillEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: sm
 * Date: 2017-07-21
 * Time: 09:10:21.127
 */

@Repository
public class TBillDaoImpl extends AbstractBaseMapper<TBillEntity> implements TBillDao {
    @Override
    public TBillEntity selectOneByBillNo(String billNo) {
        Map<String, Object> map = new HashMap<>();
        map.put("billNo", billNo);
        return getSqlSession().selectOne(getStatement("selectOneByBillNo"), map);
    }

    @Override
    public List<TBillEntity> selectListByTradeNo(String tradeNo) {
        Map<String, Object> map = new HashMap<>();
        map.put("tradeNo", tradeNo);
        return getSqlSession().selectList(getStatement("selectListByTradeNo"), map);
    }


    @Override
    public List<TBillEntity> selectPaidListByTradeNos(List<String> tradeNos) {
        Map<String, Object> map = new HashMap<>();
        map.put("tradeNos", tradeNos);
        return getSqlSession().selectList(getStatement("selectPaidListByTradeNos"), map);
    }

    @Override
    public List<TBillEntity> selectListByTradeNos(List<String> tradeNos) {
        Map<String, Object> map = new HashMap<>();
        map.put("tradeNos", tradeNos);
        return getSqlSession().selectList(getStatement("selectListByTradeNos"), map);
    }

    @Override
    public List<TBillEntity> selectListByOrderBillIds(List<Long> orderBillIds) {
        Map<String, Object> map = new HashMap<>();
        map.put("orderBillIds", orderBillIds);
        return getSqlSession().selectList(getStatement("selectListByOrderBillIds"), map);
    }

    @Override
    public List<TBillEntity> selectByMinId() {
        return getSqlSession().selectList(getStatement("selectByMinId"));
    }

    @Override
    public List<TBillEntity> selectListByRepaymentDates(List<Date> repaymentDateList, Page page) {
        Map<String, Object> map = new HashMap<>();
        map.put("repaymentDateList", repaymentDateList);
        map.put("page", page);
        return getSqlSession().selectList(getStatement("selectListByRepaymentDates"), map);
    }

    @Override
    public List<TBillEntity> selectLatestListByUserCodeAndCategoryCode(String categoryCode, String userCode, Integer size) {
        Map<String, Object> map = new HashMap<>();
        map.put("productCategory", categoryCode);
        map.put("userCode", userCode);
        map.put("size", size);
        return getSqlSession().selectList(getStatement("selectLatestListByUserCodeAndCategoryCode"), map);
    }

    /**
     * 查询逾期30天的数据
     *
     * @param lastOverTime
     */
    @Override
    public List<TBillEntity> selectMoreThan30DaysOverdueByLastOverTime(String lastOverTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("lastOverTime", lastOverTime);
        return getSqlSession().selectList(getStatement("selectMoreThan30DaysOverdueByLastOverTime"), map);
    }

    /**
     * 查询需要发送抵扣提醒短信的账单
     */
    @Override
    public List<TBillEntity> selectNeedSendDiscountRemindSmsBill(Long startId, int pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("startId", startId);
        map.put("pageSize", pageSize);
        return getSqlSession().selectList(getStatement("selectNeedSendDiscountRemindSmsBill"), map);
    }

    @Override
    public List<TBillEntity> selectTBillListForExtension(Date startDate, Date endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        return getSqlSession().selectList(getStatement("selectTBillListForExtension"), map);
    }

    /**
     * 查询需要修复抵扣字段的历史账单
     *
     * @param page
     * @return
     */
    @Override
    public List<TBillDeductFixEntity> selectWaitingFixList(Page page) {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        return getSqlSession().selectList(getStatement("selectWaitingFixList"), map);
    }

    @Override
    public List<TBillEntity> getOldUnpaidBillListByMobile(String mobile) {
        Map<String, Object> map = new HashMap<>();
        map.put("mobile", mobile);
        return getSqlSession().selectList(getStatement("getOldUnpaidBillListByMobile"), map);
    }

    @Override
    public void copyInsert(TBillEntity entity) {
        this.getSqlSession().insert(this.getStatement("copyInsert"), entity);
    }
}